﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace DevCore.Web
{
    /// <summary>
    /// 输出对像辅助类
    /// </summary>
    public class ResponseHelper
    {
        /// <summary>
        /// 客户端脚本
        /// </summary>
        /// <param name="sMsg">当前提醒内容</param>
        /// <param name="sUrl">离开的方向</param>
        public static void Message(String sMsg, String sUrl)
        {
            StringBuilder sbScript = new StringBuilder();
            sbScript.Append("<script type=\"text/javascript\">");
            sbScript.Append("alert('" + sMsg + "');");
            sbScript.Append("location.href='" + sUrl + "';");
            sbScript.Append("</script>");
            HttpContext.Current.Response.Write(sbScript.ToString());
        }

        /// <summary>
        /// 直接提醒或者不做跳转
        /// </summary>
        /// <param name="sMsg"></param>
        public static void Message(String sMsg)
        {
            StringBuilder sbScript = new StringBuilder();
            sbScript.Append("<script type=\"text/javascript\">");
            sbScript.Append("alert('" + sMsg + "');");
            sbScript.Append("</script>");
            HttpContext.Current.Response.Write(sbScript.ToString());
        }


        /// <summary>
        /// 提醒后执行script
        /// </summary>
        /// <param name="sMsg"></param>
        /// <param name="sScript"></param>
        public static void MessageByScript(String sMsg, String sScript)
        {
            StringBuilder sbScript = new StringBuilder();
            sbScript.Append("<script type=\"text/javascript\">");
            sbScript.Append("alert('" + sMsg + "');");
            sbScript.Append(sScript);
            sbScript.Append("</script>");
            HttpContext.Current.Response.Write(sbScript.ToString());
        }

        /// <summary>
        /// 执行Script脚本
        /// </summary>
        /// <param name="sScript"></param>
        public static void DoJsScript(String sScript)
        {
            StringBuilder sbScript = new StringBuilder();
            sbScript.Append("<script type=\"text/javascript\">");
            sbScript.Append(sScript);
            sbScript.Append("</script>");
            HttpContext.Current.Response.Write(sbScript.ToString());  
        }
    }
}
